﻿
using System ;

using MskEdit.Dxf.Representation ;
using MskEdit.Dxf.Model ;
using MskEdit.Sdk ;


namespace MskEdit.Dxf.Backend
{

    public static class DxfStringReader
    {        
        
        public static string TryReadAfterCode( string[] allLines, ref int lineNo, string fallbackString ) {
            return DxfLineReader.TryRead( allLines, ref lineNo, fallbackString ) ;
        }


        public static string TryRead( string code, string[] allLines, ref int lineNo, string fallbackString ) {
            return DxfLineReader.TryRead( code, allLines, ref lineNo, fallbackString ) ;
        }
               
               
        public static string TryRead( string[] allLines, ref int lineNo, string fallbackString ) {
        
            int internalLineNo = lineNo ;
            
            DxfCode dxfCode = DxfCodeReader.TryRead( allLines, ref internalLineNo, null ) ;
            if ( dxfCode == null )
                return fallbackString ;
                
            if ( ! dxfCode.HasStringCode )
                return fallbackString ;
            
            string str = TryReadAfterCode( allLines, ref internalLineNo, null ) ;
            if ( str == null )
                return fallbackString ;
            
            lineNo = internalLineNo ;
            
            return str ;
        }
    }
}
